<?php use_javascript('data/attributelist.js') ?>

<script type="text/javascript">

    $(document).ready(function(){
        $("#commit-changes").button().click(function(){
            saveChanges();
        });

        $(".remove").button({
            icons: { primary: "ui-icon-trash"}, text: true
        }).click(function(){
            remove($(this));
        });

        rowHover("");
    });


</script>

<h4 class="data">Attribute List</h4>
<table id="attribute-list" class="table-list ui-widget ui-widget-content" >
    <thead class="ui-widget-header">
        <tr>
            <td>Attribute</td><td>Value</td><td>Unit</td><td></td>
        </tr>
    </thead>
    <tbody id="attribute-list-body">
        <?php if ($pager->getResults()->count() == 0): ?>
        <tr>
            <td style="cursor: default">Your attribute list is empty.</td>
        </tr>
        <?php else: ?>
            <?php foreach($pager->getResults() as $oda): ?>
            <tr id="attr<?php echo $oda['id'] ?>">
                <td id="oda_name_<?php echo $oda['id'] ?>" width="30%" ><?php echo $oda['Attribute']['attributename'] ?></td>
                <td id="oda_value_<?php echo $oda['id'] ?>" width="10%"><?php echo $oda['attributevalue'] ?></td>
                <td id="oda_unit_<?php echo $oda['id'] ?>" width="50%"><?php echo $oda['Unit']['unit'] ?></td>
                <td nowrap style="font-size: 70%;">
                    <button class="remove" title="Remove" id="oda_remove_<?php echo $oda['id'] ?>">Remove</button>
                </td>
            </tr>
            <?php endforeach; ?>
        <?php endif;?>
    </tbody>
</table>

<div style="display: inline">
    <?php if ($pager->haveToPaginate()): ?>
        <div onclick="readPage(1)" class="link-div">
            &lt;&lt;
        </div>&nbsp;
        <div onclick="readPage(<?php echo $pager->getPreviousPage(); ?>)" class="link-div">
            &lt;
        </div>&nbsp;
        <?php foreach($pager->getLinks() as $page): ?>
            <?php if($page == $pager->getPage()): ?>
                <?php echo $page ?>&nbsp;
            <?php else: ?>
                <div onclick="readPage(<?php echo $page ?>)" class="link-div">
                    <?php echo $page ?>
                </div>&nbsp;
            <?php endif;?>
        <?php endforeach; ?>
        <div onclick="readPage(<?php echo $pager->getNextPage(); ?>)" class="link-div">
            &gt;
        </div>&nbsp;
        <div onclick="readPage(<?php echo $pager->getLastPage(); ?>)" class="link-div">
            &gt;&gt;
        </div>&nbsp;
    <?php endif; ?>
</div>

<div style="float: right; ">
    <strong><?php echo count($pager) ?></strong> attribute in this depth

    <?php if ($pager->haveToPaginate()): ?>
    - page <strong><?php echo $pager->getPage() ?>/<?php echo $pager->getLastPage() ?></strong>
    <?php endif; ?>

</div>
<p>
<button id="commit-changes">save changes</button>